<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="购车人姓名">
              <j-input v-model="queryParam.name" placeholder="请输入购车人姓名"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="手机号码">
              <j-input v-model="queryParam.contactPhone" placeholder="请输入手机号码"></j-input>
              <!-- <a-date-picker placeholder="请输入车型配置" v-model="queryParam.carTypeConfiguration"></a-date-picker> -->
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="车辆型号">
              <j-input v-model="queryParam.brand" placeholder="请输入车辆型号"></j-input>
              <!-- <a-date-picker placeholder="请输入车型配置" v-model="queryParam.carTypeConfiguration"></a-date-picker> -->
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="车辆vin码">
                <j-input v-model="queryParam.vin" placeholder="请输入车辆vin码"></j-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span class="table-page-search-submitButtons" style="float: left; overflow: hidden">
              <a-button icon="search" type="primary" @click="searchQuery">查询</a-button>
              <a-button
                icon="reload"
                style="margin-left: 8px"
                type="primary"
                @click="searchReset"
              >重置</a-button>
              <a style="margin-left: 8px" @click="handleToggleSearch">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button icon="plus" type="primary" @click="handleAdd2(2)">新增</a-button>
      <!--      <a-button @click="handleAdd3" type="primary" icon="plus">新增牵引车挂车订单</a-button>-->
<!--      <a-button icon="download" type="primary" @click="handleExportXls('cxm-订单记录信息')">导出</a-button>-->
<!--      <a-upload-->
<!--        :action="importExcelUrl"-->
<!--        :headers="tokenHeader"-->
<!--        :multiple="false"-->
<!--        :showUploadList="false"-->
<!--        name="file"-->
<!--        @change="handleImportExcel"-->
<!--      >-->
<!--        <a-button icon="import" type="primary">导入</a-button>-->
<!--      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel2">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :pagination="ipagination"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :scroll="{ x: 2000 }"
        bordered
        rowKey="id"
        size="middle"
        @change="handleTableChange"
      >
        <span slot="operation" slot-scope="text, record">
          <a-button style="margin: 0 10px 0 0" type="primary" @click="handleEdit2(record, 1)">查看</a-button>
          <a-button v-if="record.finished == '已驳回'" style="margin: 0 10px 0 0" @click="handleEdit2(record, 0)">修改</a-button>
          <a-button @click="showModal(record)">作废</a-button>
          <a-modal v-model="visible2" title="作废提示" @ok="getInfo(record)">
            <p>是否对该条记录进行作废？作废后将无法恢复！</p>
          </a-modal>
        </span>
        <template slot="status" slot-scope="text, record">
          <a-tag v-if="record.finished == '正在审批中' " color="orange">{{ record.finished }}</a-tag>
          <a-tag v-if="record.finished == '已驳回' " color="red">{{ record.finished }}</a-tag>
          <a-tag v-if="record.finished == '审批已通过' " color="green">{{ record.finished }}</a-tag>
        </template>
      </a-table>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <!-- <cxmOrderManager-modal ref="modalForm" @ok="modalFormOk"></cxmOrderManager-modal> -->
    <sales-register-model ref="modalForm" @ok="modalFormOk"></sales-register-model>
    <!--    <sales-regis-form-model ref="modalForm2" @ok="modalFormOk"></sales-regis-form-model>-->
    <cxm-order-manager-info-modal ref="cxmOrderManagerInfoModal"></cxm-order-manager-info-modal>
  </a-card>
</template>

<script>
import CxmOrderManagerModal from '../../cxm/modules/CxmOrderManagerModal.vue'
import CxmOrderManagerInfoModal from '../../cxm/modules/CxmOrderManagerInfoModal.vue'
import SalesRegisterModel from './SalesRegisterModel.vue'
// import SalesRegisFormModel from './SalesRegisFormModel.vue'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JInput from '@/components/jeecg/JInput'
import moment from 'moment'

export default {
  name: 'SalesRegister',
  mixins: [JeecgListMixin],
  components: {
    CxmOrderManagerModal,
    CxmOrderManagerInfoModal,
    SalesRegisterModel,
    // SalesRegisFormModel,
    JInput,
    moment
  },
  data() {
    return {
      description: 'cxm-订单管理页面',
      visible: false,
      visible2: false,
      // 表头
      loading: '',
      columns: [
        {
          title: '订单号',
          align: 'center',
          dataIndex: 'id'
        },
        {
          title: '购车人',
          align: 'center',
          dataIndex: 'buyerName'
        },
        {
          title: '销售员',
          align: 'center',
          dataIndex: 'sellerName'
        },
        {
          title: '车辆识别代码(VIN)',
          align: 'center',
          dataIndex: 'vin'
        },
        {
          title: '审核状态',
          align: 'center',
          dataIndex: 'finished',
          scopedSlots: { customRender: 'status' },
        },
        // {
        //   title: '交车地点',
        //   align: 'center',
        //   dataIndex: 'deliveryPlace'
        // },
        // {
        //   title: '应交付时间',
        //   align: 'center',
        //   dataIndex: 'deliveryTime'
        // },
        {
          title: '订金(元)',
          align: 'center',
          dataIndex: 'deposit'
        },
        {
          title: '车辆销售价(元)',
          align: 'center',
          dataIndex: 'price'
        },

        // {
        //   title: '代收保险费(元)',
        //   align: 'center',
        //   dataIndex: 'insuranceFee'
        // },
        // {
        //   title: '金融服务费(元)',
        //   align: 'center',
        //   dataIndex: 'financialFee'
        // },
        // {
        //   title: '上牌费(元)',
        //   align: 'center',
        //   dataIndex: 'licensePlateFee'
        // },
        // {
        //   title: '装潢费(元)',
        //   align: 'center',
        //   dataIndex: 'decorationFee'
        // },
        // {
        //   title: '二手车代销服务费(元)',
        //   align: 'center',
        //   dataIndex: 'consignmentFee'
        // },
        // {
        //   title: '(旧车)抵扣费(元)',
        //   align: 'center',
        //   dataIndex: 'deductionFee'
        // },
        {
          title: '代办服务费(元)',
          align: 'center',
          dataIndex: 'otherFees'
        },
        // {
        //   title: '备注',
        //   align: 'center',
        //   dataIndex: 'remarks'
        // },
        {
          title: '操作',
          dataIndex: 'operation',
          align: 'center',
          width: 260,
          fixed: 'right',
          scopedSlots: {
            customRender: 'operation'
          }
        }
      ],

      url: {
        list: '/sale/cxmSaleOrderInfo/list?orderType=' + 2,
        delete: '/cxm/cxmOrderManager/delete',
        deleteBatch: '/sale/cxmSaleOrderInfo/deleteOrderInfos',
        exportXlsUrl: 'cxm/cxmOrderManager/exportXls',
        importExcelUrl: 'cxm/cxmOrderManager/importExcel'
      }
    }
  },
  mounted() {
    this.loadData()
  },
  computed: {
    importExcelUrl: function() {
      return `${process.env.VUE_APP_BASE_API}/${this.url.importExcelUrl}`
    }
  },
  watch: {
    dataSource: {
      // 每个属性值发生变化就会调用这个函数
      handler(newVal, oldVal) {
        for (let i in newVal) {
          if(newVal[i].finished == 0){
            newVal[i].finished = "正在审批中"
          }else if(newVal[i].finished == 1){
            newVal[i].finished = "审批已通过"
          }else if(newVal[i].finished == 2){
            newVal[i].finished = "已驳回"
          }
        }
      },
      // 立即处理 进入页面就触发
      immediate: true,
      // 深度监听 属性的变化
      deep: true
    }
  },
  methods: {
    close() {
      this.$emit('close')
      this.visible2 = false
    },
    showModal(record) {
      this.visible2 = true
      this.onSelectedRecordId = record.id

    },
    getInfo() {
      this.axios.post('/sale/cxmSaleOrderInfo/deleteOrderInfo?id=' + this.onSelectedRecordId
      ).then(res => {
        let rs = res.result
        console.log(rs)
        this.close()
        this.loadData()
      }).catch(err => {
        // this.expRoute("2",err.message)
      })
    }
  },
  filters: {
    filterTime(time) {
      return moment(time).format('YYYY-MM-DD')
    },
    filterDepositAttribute(depositAttribute) {
      switch (depositAttribute) {
        case '1':
          return '可退'
          break
        case '2':
          return '不可退'
          break
        case '3':
          return '有条件可退'
          break
      }
    }
  }
}
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>
